//
//  BaseViewController.m
//  EverydayNews
//
//  Created by 李沛池 on 2017/7/18.
//  Copyright © 2017年 Godlike. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@property (nonatomic,copy) void (^leftBtnAction)();

@end

@implementation BaseViewController
{
    UIView *_viewNav;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initData];
    [self initUI];
    [self defaultUI];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self updateData];
    [self updateUI];
//    [self.navigationController setNavigationBarHidden:YES animated:NO];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
   
//    [self.navigationController setNavigationBarHidden:YES animated:NO];
}

- (void)initData
{
    
}

- (void)initUI
{
    
}

- (void)defaultUI
{
    //隐藏返回按钮后面的文字
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                         forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.tintColor = ColorWhite;
    
    // 方式1：使用自己的图片替换原来的返回图片
//    self.navigationController.navigationBar.backIndicatorImage = [UIImage imageNamed:@"util_nav_back"];
//    self.navigationController.navigationBar.backIndicatorTransitionMaskImage = [UIImage imageNamed:@"util_nav_back"];
}

- (void)updateData
{
    
}

- (void)updateUI
{
    
}


- (void)initNavWithTitle:(NSString *)title
{
    [self initNavWithTitle:title leftBtnImageName:nil leftActionBlock:nil];
}

- (void)initNavWithTitle:(NSString *)title leftBtnImageName:(NSString *)leftBtnImageName leftActionBlock:(void (^)())block
{
    return;
    [self initNavBg];
    [self initTitle:title];
    if (leftBtnImageName.length > 0) {
        [self initLeftBtn:leftBtnImageName];
        _leftBtnAction = block;
    }
}

- (void)initNavBg
{
    _viewNav = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
    _viewNav.backgroundColor = COLOR_FFFFFF(0xe63331);
    [self.view addSubview:_viewNav];
}

- (void)initTitle:(NSString *)title
{
    UILabel *labelTitle = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2 - 200/2, 31, 200, 22)];
    labelTitle.text = title;
    labelTitle.textColor = [UIColor whiteColor];
    labelTitle.textAlignment = NSTextAlignmentCenter;
    [_viewNav addSubview:labelTitle];
}

- (void)initLeftBtn:(NSString *)leftBtnImageName
{
    UIButton *btnLeft = [UIButton buttonWithType:UIButtonTypeCustom];
    btnLeft.frame = CGRectMake(0, 20, 44, 44);
    [btnLeft setImage:[UIImage imageNamed:leftBtnImageName] forState:UIControlStateNormal];
    [btnLeft addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [_viewNav addSubview:btnLeft];
}

- (void)leftBtnClick
{
    _leftBtnAction();
}

@end
